using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;
using SharpCore.Utilities;

namespace Dating.DA
{
	public class MemberPreferenceDA
	{
		#region Fields

		protected string connectionStringName;

		#endregion

		#region Constructors
		public MemberPreferenceDA()
		{
		}

		public MemberPreferenceDA(string connectionStringName)
		{
			ValidationUtility.ValidateArgument("connectionStringName", connectionStringName);

			this.connectionStringName = connectionStringName;
		}

		#endregion

		#region Methods

		/// <summary>
		/// Saves a record to the MemberPreference table.
		/// </summary>
		public  int Insert(MemberPreference memberPreference)
		{
			ValidationUtility.ValidateArgument("memberPreference", memberPreference);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", memberPreference.TenantID),
				new SqlParameter("@ProfileID", memberPreference.ProfileID),
				new SqlParameter("@Gender", memberPreference.Gender),
				new SqlParameter("@FromAge", memberPreference.FromAge),
				new SqlParameter("@ToAge", memberPreference.ToAge),
				new SqlParameter("@OptOutAge", memberPreference.OptOutAge),
				new SqlParameter("@ShowOnlineStatus", memberPreference.ShowOnlineStatus),
				new SqlParameter("@ShowZodiac", memberPreference.ShowZodiac),
				new SqlParameter("@FromHeight", memberPreference.FromHeight),
				new SqlParameter("@ToHeight", memberPreference.ToHeight),
				new SqlParameter("@Location", memberPreference.Location),
				new SqlParameter("@Zodiac", memberPreference.Zodiac)
			};

			memberPreference.PreferenceID = Convert.ToInt32(SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "MemberPreferenceInsert", parameters));
			return memberPreference.PreferenceID;
		}

		/// <summary>
		/// Updates a record in the MemberPreference table.
		/// </summary>
		public  int Update(MemberPreference memberPreference)
		{
			ValidationUtility.ValidateArgument("memberPreference", memberPreference);

			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@PreferenceID", memberPreference.PreferenceID),
				new SqlParameter("@TenantID", memberPreference.TenantID),
				new SqlParameter("@ProfileID", memberPreference.ProfileID),
				new SqlParameter("@Gender", memberPreference.Gender),
				new SqlParameter("@FromAge", memberPreference.FromAge),
				new SqlParameter("@ToAge", memberPreference.ToAge),
				new SqlParameter("@OptOutAge", memberPreference.OptOutAge),
				new SqlParameter("@ShowOnlineStatus", memberPreference.ShowOnlineStatus),
				new SqlParameter("@ShowZodiac", memberPreference.ShowZodiac),
				new SqlParameter("@FromHeight", memberPreference.FromHeight),
				new SqlParameter("@ToHeight", memberPreference.ToHeight),
				new SqlParameter("@Location", memberPreference.Location),
				new SqlParameter("@Zodiac", memberPreference.Zodiac)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberPreferenceUpdate", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberPreference table by its primary key.
		/// </summary>
		public  int Delete(int preferenceID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@PreferenceID", preferenceID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberPreferenceDelete", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberPreferenceDeleteAllByProfileID", parameters));
		}

		/// <summary>
		/// Deletes a record from the MemberPreference table by a foreign key.
		/// </summary>
		public  int DeleteAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			return(SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "MemberPreferenceDeleteAllByTenantID", parameters));
		}

		/// <summary>
		/// Selects a single record from the MemberPreference table.
		/// </summary>
		public  MemberPreference Select(int preferenceID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@PreferenceID", preferenceID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberPreferenceSelect", parameters))
			{
				if (dataReader.Read())
				{
					return MakeMemberPreference(dataReader);
				}
				else
				{
					return null;
				}
			}
		}

		/// <summary>
		/// Selects all records from the MemberPreference table.
		/// </summary>
		public  List<MemberPreference> SelectAll(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)
			};
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberPreferenceSelectAll", parameters))
			{
				List<MemberPreference> memberPreferenceList = new List<MemberPreference>();
				while (dataReader.Read())
				{
					MemberPreference memberPreference = MakeMemberPreference(dataReader);
					memberPreferenceList.Add(memberPreference);
				}

				return memberPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberPreference table by a foreign key.
		/// </summary>
		public  List<MemberPreference> SelectAllByProfileID(int profileID, int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@ProfileID", profileID)
,				new SqlParameter("@TenantID", tenantID)
			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberPreferenceSelectAllByProfileID", parameters))
			{
				List<MemberPreference> memberPreferenceList = new List<MemberPreference>();
				while (dataReader.Read())
				{
					MemberPreference memberPreference = MakeMemberPreference(dataReader);
					memberPreferenceList.Add(memberPreference);
				}

				return memberPreferenceList;
			}
		}

		/// <summary>
		/// Selects all records from the MemberPreference table by a foreign key.
		/// </summary>
		public  List<MemberPreference> SelectAllByTenantID(int tenantID)
		{
			SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@TenantID", tenantID)

			};

			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "MemberPreferenceSelectAllByTenantID", parameters))
			{
				List<MemberPreference> memberPreferenceList = new List<MemberPreference>();
				while (dataReader.Read())
				{
					MemberPreference memberPreference = MakeMemberPreference(dataReader);
					memberPreferenceList.Add(memberPreference);
				}

				return memberPreferenceList;
			}
		}

		/// <summary>
		/// Creates a new instance of the MemberPreference class and populates it with data from the specified SqlDataReader.
		/// </summary>
		protected  MemberPreference MakeMemberPreference(SqlDataReader dataReader)
		{
			MemberPreference memberPreference = new MemberPreference();
			memberPreference.PreferenceID = SqlClientUtility.GetInt32(dataReader, "PreferenceID", 0);
			memberPreference.TenantID = SqlClientUtility.GetInt32(dataReader, "TenantID", 0);
			memberPreference.ProfileID = SqlClientUtility.GetInt32(dataReader, "ProfileID", 0);
			memberPreference.Gender = SqlClientUtility.GetString(dataReader, "Gender", String.Empty);
			memberPreference.FromAge = SqlClientUtility.GetString(dataReader, "FromAge", String.Empty);
			memberPreference.ToAge = SqlClientUtility.GetString(dataReader, "ToAge", String.Empty);
			memberPreference.OptOutAge = SqlClientUtility.GetString(dataReader, "OptOutAge", String.Empty);
			memberPreference.ShowOnlineStatus = SqlClientUtility.GetString(dataReader, "ShowOnlineStatus", String.Empty);
			memberPreference.ShowZodiac = SqlClientUtility.GetString(dataReader, "ShowZodiac", String.Empty);
			memberPreference.FromHeight = SqlClientUtility.GetString(dataReader, "FromHeight", String.Empty);
			memberPreference.ToHeight = SqlClientUtility.GetString(dataReader, "ToHeight", String.Empty);
			memberPreference.Location = SqlClientUtility.GetString(dataReader, "Location", String.Empty);
			memberPreference.Zodiac = SqlClientUtility.GetString(dataReader, "Zodiac", String.Empty);

			return memberPreference;
		}

		#endregion
	}
}
